<template>
    <div>
        {{ info }}
        <table>
            <thead>
               
                <tr>
                    <td>姓名</td>
                    <td><input type="text" v-model="info.dName"  ></td>
                </tr> 
                <tr>
                    <td>图片</td>
                    <td><input type="file" @change="img"   >
                        <img :src="info.img" width="60" height="60" ></td>
                </tr>

                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" v-model="info.state" :value="1" >上架
                        <input type="radio" v-model="info.state" :value="0" >下架
                    </td>
                </tr>
                <tr>
                    <td>备注</td>
                    <td><input type="text" v-model="info.dbend" ></td>
                </tr>
                <tr>
                    <td>功能</td>
                    <td><select v-model="info.sId" >
                        <option value="">请选择</option>
                        <option :value="o.sId" v-for="o in fana" >{{ o.sName }}</option>
                    </select></td>
                </tr>
                
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="Add" ></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const router=useRouter();
const route=useRoute();

onMounted(()=>{
    List();
    Fand();
})

let info:any=ref({
    dId:route.query.id,
  dName: "",
  img: "",
  dbend:"",
  state: "",
  sId: "",
  isDell: 0
});

let fana:any=ref([]);

const Fand=()=>{
    axios({
        url:'https://localhost:7033/api/User/FandD',
        method:"get",
        params:{
            id:route.query.id
        }
    })
    .then((res)=>{
        console.log(res);
        
        Object.assign(info.value,res.data);
    })
}


const Add=()=>{
    axios({
        url:'https://localhost:7033/api/User/UpdfateD',
        method:'post',
        data:info.value
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0 )
    {
        alert("修改成功");
        return;
    }
    else
    {
        alert("失败");
    }
    })
    

}

const List=()=>{
    axios({
        url:'https://localhost:7033/api/User/ListS',
        method:'get'
    })
    .then((res)=>{
        console.log(res);
        fana.value=res.data
    })
}



const img=(e:any)=>{
    console.log(e);

    let obj=e.target.files[0];
    let f=new FormData();
    f.append("file",obj);

    axios({
        url:'https://localhost:7033/api/Img',
        method:'post',
        data:f
    })
    .then((res)=>{
        console.log(res.data);
        info.value.img=res.data;
    })
}



</script>

<style scoped>

</style>